package com.isnmp.nms.framework.discover.service;

import java.net.InetAddress;
import java.sql.Timestamp;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import com.isnmp.common.snmp.SNMPSysConfig;
import com.isnmp.common.snmp.SNMPTarget;
import com.isnmp.nms.framework.discover.DeviceInfo;

public class SearchNodeService {
    private List<DeviceInfo> rsList = new Vector();

    public List<DeviceInfo> searchDevice(String paramString, List<SNMPTarget> paramList, boolean paramBoolean) {
        Vector localVector = new Vector();
        localVector.add(paramString);
        return searchDeviceByNetList(localVector, paramList, paramBoolean);
    }

    public List<DeviceInfo> searchDeviceByNetList(List<String> paramList, List<SNMPTarget> paramList1, boolean paramBoolean) {
        Vector localVector = new Vector();
        Iterator localIterator = paramList.iterator();
        while (localIterator.hasNext()) {
            String str1 = (String) localIterator.next();
            int i = str1.lastIndexOf("0");
            if (i >= 0) {
                String str2 = str1.substring(0, i);
                String str3 = str2 + "1";
                String str4 = str2 + "254";
                StartEndIP localStartEndIP = new StartEndIP();
                localStartEndIP.startIP = str3;
                localStartEndIP.endIP = str4;
                localVector.add(localStartEndIP);
            }
        }
        return searchDevice(localVector, paramList1, paramBoolean);
    }

    public List<DeviceInfo> searchDevice(String paramString1, String paramString2, List<SNMPTarget> paramList, boolean paramBoolean) {
        Vector localVector = new Vector();
        StartEndIP localStartEndIP = new StartEndIP();
        localStartEndIP.startIP = paramString1;
        localStartEndIP.endIP = paramString2;
        localVector.add(localStartEndIP);
        return searchDevice(localVector, paramList, paramBoolean);
    }

    public List<DeviceInfo> searchDevice(List<StartEndIP> paramList, List<SNMPTarget> paramList1, boolean paramBoolean) {
        Vector localVector = new Vector();
        Iterator localIterator = paramList.iterator();
        while (localIterator.hasNext()) {
            StartEndIP localStartEndIP = (StartEndIP) localIterator.next();
            String str1 = localStartEndIP.startIP;
            int i = str1.lastIndexOf(".");
            String str2 = str1.substring(i + 1);
            int j = Integer.parseInt(str2);
            String str3 = str1.substring(0, i + 1);
            String str4 = localStartEndIP.endIP;
            int k = str4.lastIndexOf(".");
            String str5 = str4.substring(k + 1);
            int m = Integer.parseInt(str5);
            for (int n = j; n <= m; n++)
                localVector.add(str3 + n);
        }
        return searchDeviceByIPList(localVector, paramList1, paramBoolean);
    }

    public List<DeviceInfo> searchDeviceByIPList(List<String> paramList, List<SNMPTarget> paramList1, boolean paramBoolean) {
        int i = paramList.size();
        if (i == 0)
            return this.rsList;
        int j = i;
        int k = SNMPSysConfig.SNMPThreadPoolSize;
        if (j > k)
            ;
        j = k;
        ThreadPoolExecutor localThreadPoolExecutor = new ThreadPoolExecutor(j, j, 30L, TimeUnit.SECONDS, new LinkedBlockingQueue());
        Iterator localIterator = paramList.iterator();
        while (localIterator.hasNext()) {
            String str = (String) localIterator.next();
            localThreadPoolExecutor.execute(new IpSearchTask(str, paramList1, this.rsList, paramBoolean));
        }
        localThreadPoolExecutor.shutdown();
        try {
            for (boolean bool = false; !bool; bool = localThreadPoolExecutor.awaitTermination(1L, TimeUnit.SECONDS))
                ;
        } catch (InterruptedException localInterruptedException) {
            localInterruptedException.printStackTrace();
        }
        System.out.println("=============================");
        System.out.println(new Timestamp(System.currentTimeMillis()) + Messages.getString("SearchNodeService.6") + this.rsList.size());
        return this.rsList;
    }

    public static void main(String[] paramArrayOfString) {
        try {
            InetAddress localInetAddress = InetAddress.getByName("www.sohu.com");
            System.out.print(localInetAddress.isReachable(5000));
        } catch (Exception localException) {
            localException.printStackTrace();
        }
    }
}